-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Implement summonIgnoring
#22417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement summonIgnoring
#22417
Conversation
If we do this, I think this functionality should be also in |
It's actually macros-only for now, but of course users could just prepare their own macro method that summons what they want and returns it for use elsewhere |
@@ -928,8 +928,8 @@ trait Implicits: | |||
/** Find an implicit argument for parameter `formal`. | |||
* Return a failure as a SearchFailureType in the type of the returned tree. | |||
*/ | |||
def inferImplicitArg(formal: Type, span: Span)(using Context): Tree = | |||
inferImplicit(formal, EmptyTree, span) match | |||
def inferImplicitArg(formal: Type, span: Span, ignored: Set[Symbol])(using Context): Tree = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in this case it's overall simpler to use a default = Set.empty
for ignored
.
@@ -1679,6 +1679,8 @@ trait Implicits: | |||
else ctxImplicits.eligible(wildProto) | |||
else implicitScope(wildProto).eligible | |||
|
|||
val preEligible = | |||
prePreEligible.filter(candidate => !ignored.contains(candidate.implicitRef.underlyingRef.symbol)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will copy each list returned by eligible, so it's a significant memory churn to cater for an edge case. An improvement would use filterConserve
, but I think it's even better to add a conditional. Something like that:
var preEligible = ... // rhs of prePreEligible
if !ignored.isEmpty then
preEligible = preEligible.filter(...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, good point. Thank you!
@@ -1082,7 +1082,7 @@ trait Implicits: | |||
* it should be applied, EmptyTree otherwise. | |||
* @param span The position where errors should be reported. | |||
*/ | |||
def inferImplicit(pt: Type, argument: Tree, span: Span)(using Context): SearchResult = ctx.profiler.onImplicitSearch(pt): | |||
def inferImplicit(pt: Type, argument: Tree, span: Span, ignored: Set[Symbol])(using Context): SearchResult = ctx.profiler.onImplicitSearch(pt): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also use a default argument here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was a little concerned about how the API would look for that since we do not have access to quotes.reflect.Symbol outside of macros - probably the best solution would be something like |
@jchyb I see. I had overlooked that point. That does not seem to have an obvious solution. So I propose we defer this question and merge this PR as is. |
Related discussion: #21909
We have yet to confirm/discuss whether this should/can be merged, but otherwise I consider this a complete implementation.
One thing to note - I decided it would be better for the
ignored
list to not affect indirect implicit searches (like in thetests/run-macros/summonIgnoring-nonrecursive
test.